
package lemmatisation;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.io.Reader;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.FileOutputStream;

public class TestApp {
    private static void usage()
    {
        System.err.println("Usage: TestApp <input file> [-o <output file>]");
    }

    public static void main(String [] args) throws Throwable {
	//if (args.length < 2) {
    //        usage();
   //         return;
   //     }
   // Class stemClass = Class.forName("org.tartarus.snowball.ext." +args[0] + "Stemmer");
	Class stemClass = Class.forName("lemmatisation.frenchStemmer");
        SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
	Method stemMethod = stemClass.getMethod("stem", new Class[0]);
	//Reader reader;
	//reader = new InputStreamReader(new FileInputStream(args[1]));
	//reader = new InputStreamReader(new FileInputStream("corpus/D1.html"));
	//reader = new BufferedReader(reader);
	String reader = "anticonstitutionnellement";
	String[] readertab = reader.split(" ");
	
	List<String> readerlist = new ArrayList<String>();
	for (int m=0;m<readertab.length;m++) {
		readerlist.add(m, readertab[m]);
	}
	
	//StringBuffer input = new StringBuffer();

      //  OutputStream outstream;

	//if (args.length > 2) {
            //if (args.length == 4 && args[2].equals("-o")) {
            //    outstream = new FileOutputStream(args[3]);
            //} else {
              //  usage();
             //   return;
            //}
	//} else {
	  //  outstream = System.out;
	//}
	//Writer output = new OutputStreamWriter(outstream);
	//output = new BufferedWriter(output);

	int repeat = 1;
//	if (args.length > 4) {
//	    repeat = Integer.parseInt(args[4]);
//	}
	String result1 = "";
	String result2 = "";
	String[] resulttab; 
	String temp = "";
	
	int u = 9;
	
	Object [] emptyArgs = new Object[0];
	//int character;
	//while ((character = reader.read()) != -1)
	//while (readertab.length > 0)
	while (readerlist.size()> 0)
	{
//	    char ch = (char) character;
//	    if (Character.isWhitespace((char) ch)) {
//		if (input.length() > 0) {
		    //stemmer.setCurrent(input.toString());
			for (int j = 0; j < readerlist.size(); j++) {
			temp = temp + " " + readertab[j];
			}
			
			stemmer.setCurrent(temp);
		    for (int i = repeat; i != 0; i--) {
			stemMethod.invoke(stemmer, emptyArgs);
		    }
		    temp = stemmer.getCurrent();
		    resulttab= temp.split(" ");
		    
		    result2 = resulttab[(resulttab.length-1)] + " "+ result2;
		    
		    System.out.println("result : "+result2 );
		    System.out.println("tab : "+readerlist.size());
		    
		    readerlist.remove(readerlist.size()-1);
		    
		    //output.write('\n');
		    //input.delete(0, input.length());
		//}
	    //} else {
		//input.append(Character.toLowerCase(ch));
	    //}
		    u--;
	}
//	output.flush();
	System.out.println("Phrase: "+ reader + " -> "+ result2 );
    }
}
